from manimlib import *
from numpy import flip, insert

LV,QL,QH,JH='#75cfb8','#bbdfc8','#f0e5d8','#ffc478'

class p1(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(0.7)
        # xr=50
        x=9
        r=50/x
        abcd=Rectangle(width=x,height=r)
        o=ORIGIN+LEFT*(r-x/2)+DOWN*r/2
        p=o+LEFT*r
        b=o+LEFT*(x-r)
        c=o+RIGHT*r
        q=b+UP*(np.sqrt(2*x*r-x**2))
        cq=Line(c,q)
        arc=ArcBetweenPoints(o+RIGHT*r,p,PI)
        self.add(abcd,arc,cq)
        self.add(Line(p,b),
            Tex('A').next_to(abcd,UL),
            Tex('B').next_to(b,DOWN),
            Tex('C').next_to(abcd,DR),
            Tex('D').next_to(abcd,UR),
            Tex('P').next_to(arc,DL),
            Tex('Q').next_to(q,LEFT),
            Tex('S').next_to(arc,UP),
            Tex('QC=10'),
            Tex('S_{ABCD}=?').shift(DOWN*1.3)
        )
        self.wait()

class p2(Scene):
    def construct(self):
        # self.add(NumberPlane())
        # self.camera.frame.scale(2.7)
        # xr=50
        x=9
        r=50/x
        abcd=Rectangle(width=x,height=r)
        o=ORIGIN+LEFT*(r-x/2)+DOWN*r/2
        p=o+LEFT*r
        b=o+LEFT*(x-r)
        c=o+RIGHT*r
        q=b+UP*(np.sqrt(2*x*r-x**2))
        cq=Line(c,q)
        arc=ArcBetweenPoints(o+RIGHT*r,p,PI)
        self.add(abcd,arc,cq)
        self.add(Line(p,b),
            Tex('A').next_to(abcd,UL),
            Tex('B').next_to(b,DOWN),
            Tex('C').next_to(abcd,DR),
            Tex('D').next_to(abcd,UR),
            Tex('P').next_to(arc,DL),
            Tex('Q').next_to(q,LEFT),
            Tex('S').next_to(arc,UP),
            # Tex('QC=10'),
            # Tex('S_{ABCD}=?').shift(DOWN*1.3)
        )
        # p2
        s=arc.get_top()
        os=Line(o,s)
        oq=Line(o,q)
        bx=Brace(abcd,UP,buff=0.5)
        self.add(os,oq,bx,
            Dot(o).move_to(o),
            Tex('O').next_to(o,DOWN),
            Tex('x').next_to(bx,UP),
            Tex('r').next_to(b,UR,buff=2),
            Tex('x-r').next_to(Line(o,b),DOWN),
        )
        self.wait()